<?php
class Helper_Language{
    static private $_language;
    /****
     * $keys = array_shift($args);
     */
    static function load($keys){
        $r='';
        $language = strtolower(Q::ini('language'));
        do{
            if(strlen($keys)<=0) break; 
            $key_a=explode('/',$keys);
            $key=array_pop($key_a);
            $path=$language;
            if(count($key_a)){
                $path=$language.'/'.implode('/',$key_a);
            }
            if(!isset(self::$_language[$path])){
                $langPth=Q::ini('app_config/ROOT_DIR'). '/_lang/';
                $langfile=$langPth.$path.'.php';
                if(is_file($langfile)){
                    self::$_language[$path]=include($langfile);
                }
            }
            if (isset(self::$_language[$path][$key]))
            {
                $r = self::$_language[$path][$key];
            }
        }while(0);
        return $r;
    }
    static function fetch(){
        $args = func_get_args();
        $keys = array_shift($args);
        $language = strtolower(Q::ini('store/language'));
        $key_a=explode('/',$keys);
        $key=array_pop($key_a);
        $path='';
        if(count($key_a)){
            $path=implode('/',$key_a).'/';
        }
        if(!isset(self::$_language[$language])){
            self::$_language[$language] = Q::loadFile($language.'.php', Q::ini('app_config/ROOT_DIR'). '/_lang/'.$path, false);
        }
        if (isset($languageargs[$language][$key]))
        {
            $key = $languageargs[$language][$key];
        }
        array_unshift($args, $key);
        return call_user_func_array('sprintf', $args);
    }
}